import os
import logging

def search_and_replace(directory, old_string, new_string):
    logging.basicConfig(filename='replace.log', level=logging.INFO)
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith("config.xml"):
                file_path = os.path.join(root, file)
                with open(file_path, "r") as f:
                    content = f.read()
                    if old_string in content:
                        content = content.replace(old_string, new_string)
                        with open(file_path, "w") as f:
                            f.write(content)
                        logging.info(f"Replaced '{old_string}' with '{new_string}' in file: {file_path}")

directory = "/var/lib/jenkins/jobs"
old_string = "xx-pre-frontend-1_192.168.66.50"
new_string = "aliyun-prod-sec-1_172.16.140.109"
search_and_replace(directory, old_string, new_string)